package com.frostmourne.mxsguimaker.listeners;

import com.frostmourne.mxsguimaker.objects.PlayerData;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

public class PlayerListener implements Listener {

    @EventHandler
    public void join(PlayerJoinEvent e){
        PlayerData data = new PlayerData(e.getPlayer().getName());
        data.load();
        PlayerData.DATA_MAP.put(data.getName(),data);
    }

    @EventHandler
    public void quit(PlayerQuitEvent e){
        PlayerData data = PlayerData.getPlayerData(e.getPlayer());
        data.save();
        PlayerData.DATA_MAP.remove(e.getPlayer().getName());
    }

}
